package examples
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import com.wskeee.ec.components.Button;
	import com.wskeee.ec.components.CheckBox;
	import com.wskeee.ec.components.Label;
	import com.wskeee.ec.components.RadioButton;
	import com.wskeee.ec.components.RadioButtonGroup;
	import com.wskeee.ec.containers.Container;
	import com.wskeee.ec.containers.HBox;
	import com.wskeee.ec.containers.VBox;
	
	public class ButtonExample extends Sprite
	{
		public function ButtonExample()
		{
			super();
		}
		
		public static function createButton():Container
		{
			var mainBox:VBox = new VBox();
			mainBox.verticalGap = 5;
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			var hbox:HBox,vbox:VBox,button:Button,label:Label;
			//头
			label = new Label();
			label.text = "按钮区";
			mainBox.addChild(label);
			//---------------------
			//正常
			//---------------------
			hbox = new HBox();
			hbox.horizontalGap = 20;
			button = new Button();
			label = new Label();
			label.text = "正常 Button"
			hbox.addChild(button);
			hbox.addChild(label);
			mainBox.addChild(hbox);
			//---------------------
			//toggon = true
			//---------------------
			hbox = new HBox();
			hbox.horizontalGap = 20;
			button = new Button();
			button.toggle = true;
			button.addEventListener(Event.CHANGE,function(evt:Event):void{});
			label = new Label();
			label.text = "toggle = true"
			hbox.addChild(button);
			hbox.addChild(label);
			mainBox.addChild(hbox);
			//---------------------
			//radioButton
			//---------------------
			var rb:RadioButton;
			var radioButtonLableA:Label = new Label();
			var radioGroupA:RadioButtonGroup;
			vbox = new VBox();
			vbox.verticalGap = 5;
			rb = new RadioButton();
			rb.label = "RadioButton A.A";
			rb.value = "groupA.A"
			rb.groupName = "GroupA";
			vbox.addChild(rb);
			rb = new RadioButton();
			rb.label = "RadioButton A.B";
			rb.value = "groupA.B"
			rb.groupName = "GroupA";
			radioGroupA = rb.group;
			radioGroupA.addEventListener(Event.CHANGE,function(evt:Event):void
			{
				radioButtonLableA.text = "selected value: "+radioGroupA.value.toString(); 
			});
			vbox.addChild(rb);
			vbox.addChild(radioButtonLableA);
			radioButtonLableA.text = "selected value: null";
			mainBox.addChild(vbox);
			
			hbox = new HBox();
			hbox.horizontalGap = 10;
			button = new RadioButton();
			button.label = "T";
			RadioButton(button).groupName = "GroupB";
			hbox.addChild(button);
			button = new RadioButton();
			button.label = "F";
			RadioButton(button).groupName = "GroupB";
			hbox.addChild(button);
			mainBox.addChild(hbox);
			//---------------------
			//checkBox
			//---------------------
			hbox = new HBox();
			hbox.horizontalGap = 10;
			var cbLabel:Label = new Label();
			var cb:CheckBox;
			var cbs:Vector.<CheckBox> = new Vector.<CheckBox>(4);
			for(var i:int=0;i<3;i++)
			{
				cb = new CheckBox();
				cb.label = "ck"+i;
				cb.addEventListener(Event.CHANGE,checkChange);
				cbs[i] = cb;
				hbox.addChild(cb);
			}
			hbox.addChild(cb);
			mainBox.addChild(hbox);
			mainBox.addChild(cbLabel);
			function checkChange(evt:Event):void
			{
				var cv:String = "value = ";
				for(i=0;i<3;i++)
				{
					if(cbs[i].selected)
						cv+=(i==0 ? "" : ",")+cbs[i].value;
				}
				cbLabel.text = cv;
			}
			
			return mainBox;
		}
	}
}